package com.boe.common.model;


import com.boe.common.util.AnnotationUtil;
import com.boe.common.util.ListUtil;
import com.boe.common.util.freemark.mvc.FreemarkerHas;
import lombok.AccessLevel;
import lombok.*;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.lang.reflect.Field;
import java.util.List;
import java.util.stream.Collectors;


@Data
@NoArgsConstructor
public class MvcCodeTemplateData extends BaseFreemarkerModel {
    private String pkg;
    private String group;

    private String entityName;
    private String entityCn;


    private Class entityClass;

    private String tableName;

    private List<Field> fields;

    private List<String> columns;

    @Setter(AccessLevel.NONE)
    private FreemarkerHas has = new FreemarkerHas();

    public MvcCodeTemplateData(String pkg, String group, Class entityClass) {
        this.pkg = pkg;
        this.group = group;
        this.entityClass = entityClass;

        this.entityName = entityClass.getSimpleName();
        this.entityCn = AnnotationUtil.getCnValue(entityClass);
        this.tableName = AnnotationUtil.getTableName(entityClass);


        this.fields = ListUtil.fromArray(this.entityClass.getDeclaredFields());

        this.columns = this.fields.stream().map(it -> AnnotationUtil.getTableField(it)).collect(Collectors.toList());
    }

}
